angular.module('app').directive('loading', [function () {
    return {
        restrict: 'A',
        scope: {
            loading: '<'
        },
        link: function (scope, el) {
            var cancel = scope.$watch('loading', function (nv) {
                if(nv && nv.then){
                    el.addClass('loading');
                    nv.then(function () {
                        el.removeClass('loading');
                    });
                    cancel();
                }
            });
        }
    }
}]);